{-# OPTIONS -XTypeOperators #-}

module Sim.Star (
   Star(..),

   genRandomStars,
   genStarsFromFile,
 ) where

import System.Random ( randomRIO )
import Sim.Helper    ( unsafeSequenceIO )
import Sim.PhysTypes

data Star = Star (Double->Double) SpType Magnitude (Double,Double) deriving Show

genStarsFromFile :: FilePath -> FiledView -> [SpType] -> IO [Star]
genStarsFromFile = undefined

--genRandomStars :: [SpType] -> FiledView -> Number -> IO [Star]
genRandomStars :: [(SpType,Double->Double)] -> FiledView -> Number -> IO [Star]
genRandomStars sp a n = do
  unsafeSequenceIO $ replicate n $ genStar a sp

--genStar :: FiledView -> [SpType] -> IO Star
genStar :: FiledView -> [(SpType,Double->Double)] -> IO Star
genStar ((x0,y0),(x1,y1)) sp =
 do
   let n = length sp - 1

   i <- randomRIO (   0, n   )
   m <- randomRIO (15.0, 23.0)
   x <- randomRIO (  x0, x1  )
   y <- randomRIO (  y0, y1  )

   return $ Star (snd $ sp !! i) (fst $ sp !! i) m (x,y)